<?php
	$query = 'select * from '.$table.' where id='.$post_id;
	$children = false;
	$labels = array();
	unset($_SESSION['return_path']);

	switch($table) {

		case 'subscription_types':
			$query = 'select id, label, freedays, dailyrate, price from subscription_types where id='.$post_id;
			$labels = array('id', 'Title', /*'Duration (days)',*/ 'Free Days', 'Daily Rate', 'Price');
			$children = true;
			$_SESSION['return_path'] = DOC_ROOT.$table.'/view/'.$post_id;
			$table = 'subscriptions';
			break;

		case 'invoices':
			$query = 'select * from '.$table.' where id='.$post_id;
			$labels = array('id', 'Date', 'User', 'Invoice Number', 'Amount', 'Details', 'Paid', 'Completed');
			break;

		case 'users':
			$query = 'select id, title, name, position, company, mob, email, address, province, linkedin, facebook, twitter, linked, verified, accesscode from '.$table.' where id='.$post_id;
			$labels = array('id', 'Title', 'Name', 'Position', 'Company', 'Mobile Number', 'Email', 'Address', 'Province', 'LinkedIn URL', 'Facebook URL', 'Twitter URL', 'Registered via LinkedIn', 'Email Verified', 'Access Code');
			break;

		case 'companies':
			$children = true;
			$_SESSION['return_path'] = DOC_ROOT.$table.'/view/'.$post_id;
			$query = 'select id, company, name, mob, email, address, province, verified, accesscode from users where id='.$post_id;
			$labels = array('id', 'Title', 'Account Manager Name', 'Account Manager Mobile Number', 'Account Manager Email', 'Address', 'Province', 'Email Verified', 'Access Code');

			$table = 'company_users';

			break;

		case 'buildings':
			$children = true;
			$_SESSION['return_path'] = DOC_ROOT.$table.'/view/'.$post_id;
			$labels = array('id', 'Title', 'Manager Name', 'Telephone Number', 'Mobile Number', 'Email', 'Address', 'Province');
			$table = 'spaces';
			break;

		case 'bookings':
			$query = 'select bookings.start, bookings.end, bookings.occupants, spaces.label, bookings.services, bookings.userid from bookings INNER JOIN spaces ON bookings.spaceid = spaces.id where bookings.id='.$post_id;
			$labels = array('Start Time', 'End Time', 'Occupants', 'Space', 'Services', 'User');
			break;

		case 'alerts':
			$query = 'select alerts.id, alerts.date, logs.description, logs.userid from alerts inner join logs on alerts.logid = logs.id where alerts.id='.$post_id;
			$labels = array('id', 'Date', 'Description', 'User');
			$cn->Update('alerts', $post_id, array('viewed'=>1), false);
			break;

		case 'training':
			$labels = array('id', 'Label', 'Description', 'Start Time', 'End Time', 'Minimum Capacity', 'Maximum Capacity', 'Price per delegate');
			break;
	}

	if ($admin == 0) $query .= ' and userid='.$user_id;
	echo $cn->OutputTableItem($query, $labels, 4, 'table view-table', false);

	/*foreach ($result[0] as $key => $value) {
		echo "$key: $value<br/>";
	}*/
	//echo $query;
?>